package com.llg.controller;

import com.llg.model.BoxVO;
import com.llg.model.response.DataResult;
import com.llg.model.response.PageResult;
import com.llg.model.response.ResponseResult;
import com.llg.service.BoxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "箱体接口")
@RestController
@RequestMapping("/box")
public class BoxController {

    private final BoxService boxService;

    @Autowired
    public BoxController(BoxService boxService) {
        this.boxService = boxService;
    }

    @GetMapping("/findAll")
    @ApiOperation(value = "查询所有箱体")
    public PageResult<BoxVO> findAll(){
        return boxService.findAll();
    }

    @GetMapping("/findOne/{id}")
    @ApiOperation(value = "通过id查询箱体")
    public DataResult<BoxVO> findOne(@PathVariable("id") int id){
        return boxService.findOne(id);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增箱体")
    public DataResult<BoxVO> add(@RequestBody BoxVO boxVO){
        return boxService.add(boxVO);
    }

    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除箱体")
    public ResponseResult delete(@PathVariable("id") int id){
        return boxService.delete(id);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改箱体")
    public ResponseResult update(@RequestBody BoxVO boxVO){
        return boxService.update(boxVO);
    }
}
